<template>
  <div style='margin-bottom: 80px;'>
    <a-divider orientation='left'>上期发货明细</a-divider>
    <f-table ref='table1' :scroll='{x:2500,y:500}' rowKey='orderDetailsId' :tableColumns='financeDetailsColumns' size='small' :showTotal='true' handler='sfinacePageListHandler' :autoLoad='false' :params='queryParam' :api='api.bod' :multiple='false'>
      <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table1')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
      </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
    </f-table>
    <a-divider orientation='left' v-if='orderDetailList&&orderDetailList.length>0'>本期发货明细</a-divider>
    <f-table ref='table6'  :scroll='{x:true}' v-if='orderDetailList&&orderDetailList.length>0' :showTotal='true' rowKey='financeDetailsId' :tableColumns='financeDetailsColumns' size='small' :dataSource='orderDetailList' :showPagination='false' :multiple='false'>
       <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table6')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
       </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='lastReturnList&&lastReturnList.length>0'>本期回上期回款</a-divider>
    <f-table ref='table2' :scroll='{x:true}' style='width: 90%' v-if='lastReturnList&&lastReturnList.length>0' :showTotal='true' rowKey='financeDetailsId' :tableColumns='lastReturnColumn' size='small' :dataSource='lastReturnList' :showPagination='false' :multiple='false'>
      <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table2')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
      </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='lastFkList&&lastFkList.length>0'>本期返上期返款</a-divider>
    <f-table ref='table3' :scroll='{x:true}' style='width: 90%' v-if='lastFkList&&lastFkList.length>0' :showTotal='true' rowKey='financeDetailsId' :tableColumns='lastFkColumn' size='small' :dataSource='lastFkList' :showPagination='false' :multiple='false'>
       <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table3')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
       </span>
    </f-table>

    <a-divider orientation='left' v-if='lastDfList&&lastDfList.length>0'>本期垫付上期垫付款</a-divider>
    <f-table ref='table4' :scroll='{x:true}' style='width: 90%' v-if='lastDfList&&lastDfList.length>0' :showTotal='true' rowKey='financeDetailsId' :tableColumns='lastDfColumn' size='small' :dataSource='lastDfList' :showPagination='false' :multiple='false'>
       <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table4')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
       </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
    </f-table>

    <a-divider orientation='left' v-if='lastTdList&&lastTdList.length>0'>本期退上期垫付款</a-divider>
    <f-table ref='table5' :scroll='{x:true}' style='width: 90%' v-if='lastTdList&&lastTdList.length>0' :showTotal='true' rowKey='financeDetailsId' :tableColumns='lastTdColumn' size='small' :dataSource='lastTdList' :showPagination='false' :multiple='false'>
      <span slot='action' slot-scope='text, record'>
      <template>
        <a href='javascript:;' @click="updateRenkuan(record,'table5')">调账</a>
        <a-divider type='vertical' />
        <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
      </template>
      </span>
      <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
    </f-table>

    <a-modal title='调整认款月份' :visible='renkuanModal' width='500px' @cancel='renkuanCancel' @ok='renkuanSubmit'>
      <f-form ref='form' :action='api.bod.updateRenkuan' :form-key='this.formItem.orderDetailsId'>
        <f-form-item label='认款月份' type='month' name='renkuanDate' :value='formItem.renkuanDate' />
        <f-form-item label='返款月份' type='month' name='supplierRetDate2' :value='formItem.supplierRetDate2' />
      </f-form>
    </a-modal>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>
<script>

import api from "./js/api"
import OrderInfoDrawer from "@/views/module/business/order/order_info_drawer"
export default {
  name: "financeDetails",
  components: { OrderInfoDrawer },
  data() {
    return {
      api: Object.assign(api, this.api),
      disabled: false,
      //列表初始化查询参数
      queryParam: {
        deptId: ""
      },
      renkuanModal: false,
      tableName:'',
      orderDetailList: [],
      lastDetailList: [],
      lastReturnList: [],
      lastFkList: [],
      lastDfList: [],
      lastTdList: [],
      financeDetailsColumns: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,

          dataIndex: "saleDate"
        },
        {
          title: '供方资信',
          align: 'left',
          width: 80,
          dataIndex: 'supplierBondType',
          scopedSlots: { customRender: 'supplierBondType' }
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 50,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "回款金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnAmount"
        }, {
          title: "回款日期",
          align: "left",
          width: 70,
          dataIndex: "returnDate"
        }, {
          title: "认款月份",
          align: "left",
          width: 60,
          dataIndex: "renkuanDate"
        }, {
          title: "公司垫款",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierPayBond"
        }, {
          title: "垫付日期",
          align: "left",
          width: 60,
          dataIndex: "supplierBondPayDate"
        }, {
          title: "成本价",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "costPrice"
        }, {
          title: "成本金额",
          align: "left",
          width: 60,
          dataIndex: "costAmount"
        }, {
          title: "供方高开税金",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierGapUpTaxesAmount"
        }, {
          title: "已付结算",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "settleRealAmount"
        }, {
          title: "供方返款费率",
          align: "left",
          width: 70,
          dataIndex: "supplierSettleRate"
        }, {
          title: "供方应返",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierRetable"
        }, {
          title: "供方实返",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierRealAmount"
        }, {
          title: "实返日期",
          align: "left",
          width: 60,
          dataIndex: "supplierRetDate"
        }, {
          title: "供方开票金额",
          align: "left",
          needTotal: true,
          width: 70,
          dataIndex: "invoicePaymentAmount"
        }, {
          title: "退垫付款",
          align: "left",
          needTotal: true,
          width: 60,
          dataIndex: "returnCustomBond"
        }, {
          title: "退款日期",
          align: "left",
          width: 60,
          dataIndex: "supplierRetBondDate"
        }
      ],
      lastReturnColumn: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: '供方资信',
          align: 'left',
          width: 80,
          dataIndex: 'supplierBondType',
          scopedSlots: { customRender: 'supplierBondType' }
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "回款金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnAmount"
        }, {
          title: "回款日期",
          align: "left",
          width: 60,
          dataIndex: "returnDate"
        }, {
          title: "认款月份",
          align: "left",
          width: 60,
          dataIndex: "renkuanDate"
        }
      ],
      lastFkColumn: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: '供方资信',
          align: 'left',
          width: 80,
          dataIndex: 'supplierBondType',
          scopedSlots: { customRender: 'supplierBondType' }
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "应返金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierRetable"
        }, {
          title: "实返金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierRealAmount"
        }, {
          title: "返款日期",
          align: "left",
          width: 70,
          dataIndex: "supplierRetDate"
        }
      ],
      lastDfColumn: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: '供方资信',
          align: 'left',
          width: 80,
          dataIndex: 'supplierBondType',
          scopedSlots: { customRender: 'supplierBondType' }
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "垫付金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "supplierPayBond"
        }, {
          title: "垫付日期",
          align: "left",
          width: 60,
          dataIndex: "supplierBondPayDate"
        }
      ],
      lastTdColumn: [
        {
          title: "操作",
          align: "left",
          width: 80,
          dataIndex: "action",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "100px",
          dataIndex: "orderNo"
        },
        {
          title: "发货日期",
          align: "left",
          width: 60,
          dataIndex: "saleDate"
        },
        {
          title: '供方资信',
          align: 'left',
          width: 80,
          dataIndex: 'supplierBondType',
          scopedSlots: { customRender: 'supplierBondType' }
        },
        {
          title: "购货方",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          width: 130,
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "规格",
          align: "left",
          width: 60,
          dataIndex: "drugsSpec"
        }, {
          title: "数量",
          align: "left",
          width: 60,
          dataIndex: "saleNum"
        }, {
          title: "单价",
          align: "left",
          width: 50,
          dataIndex: "salePrice"
        }, {
          title: "发货金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "saleAmount"
        }, {
          title: "退垫付金额",
          align: "left",
          width: 60,
          needTotal: true,
          dataIndex: "returnSupplierBond"
        }, {
          title: "退垫付日期",
          align: "left",
          width: 60,
          dataIndex: "supplierRetBondDate"
        }
      ],
      formItem: this.getFormItem(),
      saleManForm: {}
    }
  },
  created() {
  },
  methods: {
    getFormItem() {
      return {
        settleId: "",
        deptId: "",
        bankId: null,
        selectIds: "",
        amount: 0,
        settleType: 1,
        amountDate: "",
        remark: ""
      }
    },
    setData(data) {
      if (data && data.sfinanceId) {
        this.queryParam.sfinanceId = data.sfinanceId
        //查询已结算明细
        this.http.get(this, {
          url: this.api.bsd.list,
          params: {
            sfinanceId: data.sfinanceId
          },
          success: function(me, data) {
            me.orderDetailList = data.orderDetailList
            me.lastReturnList = data.lastReturnList
            me.lastFkList = data.lastFkList
            me.lastDfList = data.lastDfList
            me.lastTdList = data.lastTdList
            me.$refs["table1"].refresh(false)
          }
        })
      }
    },
    updateRenkuan(record,tableName) {
      this.formItem = record
      this.tableName=tableName;
      this.renkuanModal = true
    },
    renkuanCancel() {
      this.renkuanModal = false
    },
    renkuanSubmit() {
      this.$refs.form.submit({
        orderDetailsId: this.formItem.orderDetailsId
      }, () => {
        //this.$refs[this.tableName].refresh(false)
        this.renkuanCancel()
      })
    }
  }
}
</script>
